home *** CD-ROM | disk | FTP | other *** search
-
- /* File : drawpoly.c */
- /* Entered by : A. Wayner */
- # include <graphics.h>
- # include <stdlib.h>
-
- int y[5] = {2, 1, 4, 5, 4 };
- int x[5] = {10, 20, 30, 40, 50};
-
- main()
- {
- int graphdriver = DETECT, graphmode, i,
- maxy = 5,
- maxx = 50,
- numpt,
- maxheight, maxwidth, xscale, yscale,
- plotdata[10];
-
- numpt = sizeof( y ) / sizeof( int );
-
-
- /* Detect adapter type and initialize */
- /* graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc" );
- settextstyle( TRIPLEX_FONT, HORIZ_DIR, 2 );
- outtextxy( 100, 10, "x-y graphs using 'drawpoly'");
-
- /* Now draw the x-y graph */
- maxheight = getmaxy() - 100;
- yscale = maxheight / maxy;
-
- maxwidth = getmaxx() - 300;
- xscale = maxwidth / maxx;
-
-
- setviewport( 100, 50, 100 + maxwidth, 50 + maxheight, 1 );
- rectangle( 0,0, maxwidth, maxheight );
-
- /* Scale the data points to fit */
- /* in assigned area */
- for( i = 0; i < numpt; i++ )
- {
- plotdata[2*i] = x[i]*xscale ;
- /* Our y-coordinates increase as we go up */
- plotdata[2*i+1] = maxheight - y[i]*yscale;
- }
-
- drawpoly( numpt, plotdata ); /* Use drawpoly to display the graph */
-
- getch();
- closegraph();
- }
-
-